
import { ADD_LOADING_NUM, REDUCE_LOADING_NUM, RESET_LOADING_NUM } from './homeTypes'
const defaultState = {
    loadingNum: 0
}
const HomeReducer = (state = defaultState, action) => {
    if (action.type === ADD_LOADING_NUM) {//增加
        let initState = JSON.parse(JSON.stringify(state));
        initState.loadingNum = initState.loadingNum + 1;
        return initState;
    }
    if (action.type === REDUCE_LOADING_NUM) {//减少
        let initState = JSON.parse(JSON.stringify(state));
        if (initState.loadingNum > 0) initState.loadingNum = initState.loadingNum - 1;
        return initState;
    }
    if (action.type === RESET_LOADING_NUM) {//重置
        let initState = JSON.parse(JSON.stringify(state));
        initState.loadingNum = 0;
        return initState;
    }
    return state;
}
export default HomeReducer